/**
 * 服务器交互
 */

define(function (require, exports, module) {
    var aw = require("ajaxwrapper");
    var moment = require("moment");
    module.exports = {
    	
    	saveSignup:function(widget,formData,callback){
    		var data = {
    			signUpRegister:[]
    		}
    		var signUpRegister = [];
    		
    		var isMember = formData.member == "true" ? true:false;
    		
    		var isCustomer = formData.customer == "true" ? true : false;
    		
    		if(!isMember){
    			signUpRegister.push({
    				"member":formData.member,
    				"customer":formData.customer,
    				"pkSignUpRegister":formData.pkSignUpRegister,
    				"version":formData.version,
    				"personalInfo.name":formData["personalInfo.name"],
    				"personalInfo.mobilePhone":formData["personalInfo.mobilePhone"],
    				"personalInfo.idNumber":formData["personalInfo.idNumber"] == "" ? $("input[name='idNumberSearch']").val() : formData["personalInfo.idNumber"],
    				"personalInfo.sex":formData["personalInfo.sex"],
    				"personalInfo.version":formData["personalInfo.version"],
    				"travelContract":formData["pkTravelContract"],
    				"contactName" : formData.contactName,
    				"contactPhone" : formData.contactPhone,
    			});    			
    		}else{
    			signUpRegister.push({
    				"pkSignUpRegister":formData.pkSignUpRegister,
    				"version":formData.version,
    				"member":formData.member,
    				"customer":formData.customer,
    				"contactName" : formData.contactName,
    				"contactPhone" : formData.contactPhone,
    				"personalInfo":formData["personalInfo.pkPersonalInfo"],
    				"travelContract":formData["pkTravelContract"]
    			});	
    		}
//    		data.signUpRegister = signUpRegister;
    		data = signUpRegister[0];
    		
    		data = aw.customParam(data);
    		
    		data +="&checkInDate="+widget.get("form").getValue("checkInDate");
    		data +="&checkOutDate="+widget.get("form").getValue("checkOutDate");
    		data +="&pkPersonalInfo="+formData["personalInfo.pkPersonalInfo"];
    		
    		aw.saveOrUpdate("api/signupregister/savecustomer",data,function(datas){
    			aw.ajax({
    				url : "api/signupregister/query",
    				data : {
    					"pkSignUpRegister" : datas.pkSignUpRegister,
    					"validatePrivilege" : "false",
    					fetchProperties : "*,contactName,contactPhone,personalInfo.*,travelContract.*,travelContract.member.personalInfo.*," +
    							"travelContract.productRule.product.name"
    				},
    				dataType : "json",
    				success : function(data2){
    					callback(data2);
    				}
    			})
			});
    	}
    	
    };
});
